<script>
function del(){
if(!confirm("您确认要删除改问题吗？"))
{
return false;
}
}
</script>

<div id="ask-detail">
    <div  id="ask-detail-title">
        <h1><?php echo $model->title; ?></h1>
        <a id="reply-btn" class="btn btn-primary"  href="#reply-form">回复</a>
        <?php if (Yii::app()->user->checkAccess('admin') || Yii::app()->user->id == $model->user_id):?>
        <a id="reply-btn" class="btn btn-success"  href="<?php echo yii::app()->baseUrl.'/ask/update/'.$model->ask_id;?>">编辑</a>
        <?php endif;?>
        <?php if (Yii::app()->user->checkAccess('admin')):?>
        <a id="reply-btn" class="btn btn-warning"  href="<?php echo yii::app()->baseUrl.'/ask/delete/'.$model->ask_id;?>" onclick="return del()">删除</a>
        <?php endif;?>

   </div>

    <div class="clear"></div>
</div>
<?php
$floorID = $page->pageSize * $page->currentPage + 1;

foreach ($model->askReplies as $reply) :
    if ($reply->isFloor == 1) :
        ?>
        <div id="reply">
            <div id="reply-user" class="col-xs-3 col-md-3 col-sm-3 col-lg-3 user-info">
                <?php if ($reply->user->user_id == $model->user_id) : ?>
                    <img class="lz" src="<?php echo Yii::app()->baseUrl ?>/themes/abound/img/lz.png" alt="楼主" />
                <?php endif; ?>
                <ul>
                    <li>
                        <?php echo $reply->user->user_name; ?>
                    </li>
                    <li>
                        <?php if ($reply->user->checkAccess('admin')):?>
                        <?php echo '系统管理员'; ?>
                        <?php else:?>
                        <?php echo '普通用户'; ?>
                        <?php endif;?>
                    </li>
                    <li>
                        <?php echo $reply->user->email_address; ?>
                    </li>

                    <li>
                        <?php echo $reply->user->job_number; ?>
                    </li>
                    <li>
                        <?php echo $reply->user->nick_name; ?>
                    </li>
                    <li>
                        <?php echo $reply->user->school_name; ?>
                    </li>
                </ul>
            </div>

            <div id="reply-content" class="col-xs-9 col-md-9 col-sm-9 col-lg-9 ask-reply-content">
                <div class="content-body">
                    <?php echo $reply->body ?>
                </div>
                <div id="reply-info" class=" content-bottom">
                    <div class="date-info">
                        <ul>
                            <li><a href="<?php echo Yii::app()->request->baseUrl; ?>/message/composetoadmin"><?php echo Yii::t('ask/views', 'Inform Against') ?></a> | </li>
                            <li> <?php echo $floorID . ' ' . Yii::t('ask/views', 'Floor') ?></li>
                            <li> <?php echo $reply->createdOn ?> </li>
                            <li id="reply-open-<?php echo $floorID ?>">

                                <?php if ($reply->floorReplyCount > 0) : ?>
                                    <a href="#"  class="reply-open"><?php echo Yii::t('ask/views', 'Reply') . '(' . $reply->floorReplyCount . ')' ?></a>
                                <?php elseif ($model->isClose): ?>
                                    <?php echo Yii::t('ask/views', 'Reply'); ?>
                                <?php else : ?>
                                    <a href="#"  class="reply-open"><?php echo Yii::t('ask/views', 'Reply'); ?></a>
                                <?php endif; ?>

                                <span class="reply-close">
                                    <a href="#" ><?php echo Yii::t('ask/views', 'Close'); ?></a>
                                </span>
                            </li>
                        </ul>
                    </div>

                    <!-- floor reply  -->
                    <div id="floor-<?php echo $floorID; ?>" class="span11 floor-replies">
                        <div class="border-top"></div>
                        <div class="floor-replied">
                            <ul>
                                <?php
                                $j = 0;
                                foreach ($reply->floorReplies as $floorReply) :
                                    if (isset($floorReply->replies)) :
                                        $j++;
                                        if ($j <= 5) :
                                            ?>
                                            <li>
                                                <?php echo CHtml::link($floorReply->replies->user->user_name, array('user/view', 'id' => $floorReply->replies->user->user_id), array('class' => 'user-name')); ?> ：
                                                <span class="floor-replied-content"><?php echo strip_tags($floorReply->replies->body, '<img>'); ?></span>
                                                <br/>
                                                <div class="floor-info">
                                                    <a href="<?php echo Yii::app()->request->baseUrl; ?>/message/composetoadmin"><?php echo Yii::t('ask/views', 'Inform Against') ?></a> | 
                                                    <span class="floor-replied-date"><?php echo $floorReply->replies->createdOn; ?>&nbsp;</span>
                                                    
                                                     <?php if (!$model->isClose): ?>
                                                        <a href="#" class="floor-reply" textarea="Floor_Reply_body_<?php echo $floorID; ?>"><?php echo Yii::t('ask/views', 'Reply'); ?></a>
                                                     <?php endif; ?>
                                                </div>
                                            </li>
                                        <?php else : ?>
                                            <?php if ($j == 6) : ?><span id="show-all-reply-<?php echo $floorID; ?>" class="show-hide-reply"><a href="#"> <?php echo Yii::t('ask/views', 'Show All') ?></a></span> <?php endif; ?>

                                            <li class="over-count" hidden="hidden">
                                                <?php echo CHtml::link($floorReply->replies->user->user_name, array('user/view', 'id' => $floorReply->replies->user->user_id), array('class' => 'user-name')); ?> ：
                                                <span class="floor-replied-content"><?php echo strip_tags($floorReply->replies->body, '<img>'); ?></span>
                                                <br/>
                                                <div class="floor-info">
                                                    <a href="<?php echo Yii::app()->request->baseUrl; ?>/message/composetoadmin"><?php echo Yii::t('ask/views', 'Inform Against') ?></a> | 
                                                    <span class="floor-replied-date"><?php echo $floorReply->replies->createdOn; ?>&nbsp;</span>
                                                    
                                                    <?php if (!$model->isClose): ?>
                                                        <a href="#" class="floor-reply" textarea="Floor_Reply_body_<?php echo $floorID; ?>"><?php echo Yii::t('ask/views', 'Reply'); ?></a>
                                                    <?php endif; ?>
                                                </div>
                                            </li>
                                        <?php
                                        endif;
                                    endif;
                                endforeach;
                                ?>
                                <span id="hide-reply-<?php echo $floorID; ?>" hidden="hidden"  class="show-hide-reply"><a href="#"> <?php echo Yii::t('ask/views', 'Hide') ?></a></span> 

                                
                                 <?php if (!$model->isClose): ?>
                                <li>
                                    <div class="floor-new-reply form">
                                        <?php
                                        $form = $this->beginWidget('CActiveForm', array(
                                            'id' => 'floor-reply-form_' . $floorID,
                                            'htmlOptions' => array(
                                                'class' => 'floor-reply-form'
                                            ),
//                                                                    'enableAjaxValidation'=>true,
                                            'clientOptions' => array(
                                                'validateOnSubmit' => true,
                                            ),
                                            'enableClientValidation' => TRUE,
                                        ));
                                        ?>

                                        <div class="floor-reply-content row">
                                            <?php // echo $form->errorSummary($reply) ?>
                                            <textarea rows="3" name="AskReply[body]" id="AskReply_body"  mark="Floor_Reply_body_<?php echo $floorID?>"></textarea>
                                            <?php // echo $form->textArea($reply, 'body', array('row' => 3, 'id' => 'Floor_Reply_body_' . $floorID)) ?>
                                            <?php echo $form->error($reply, 'body'); ?>
                                        </div>
                                        <input hidden="hidden" name="AskReply[isFloor]" value="0" />
                                        <input hidden="hidden" name="AskReply[be_replied_id]" value="<?php echo $reply->reply_id; ?>" />
                                        <div class="submit-btn">
                                            <?php if (CCaptcha::checkRequirements()): ?>
                                                <div class="verify-code" >
                                                    <div style="display:inline-block">
                                                        <?php echo $form->labelEx($reply, 'verifyCode');?>
                                                    </div>
                                                    <span>
                                                        <?php echo $form->textField($reply, 'verifyCode', array('class' => 'floor-verifyCode', 'placeholder' => Yii::t('ask/views', 'Please enter the code'))); ?>
                                                        <?php
                                                        $this->widget('CCaptcha', array(
                                                            'clickableImage' => true,
                                                            'showRefreshButton' => false,
                                                            'imageOptions' => array(
                                                                'height' => '50px',
                                                                'width' => '60px',
                                                            )
                                                        ));
                                                        ?>
                                                    </span>
                                                </div>
                                                <?php echo $form->error($reply, 'verifyCode'); ?>
                                            <?php endif; ?>
                                            <input type="submit" name="floor-reply-form_<?php echo $floorID; ?>" class='btn btn-primary' value="<?php echo Yii::t('ask/views', 'Reply'); ?>">
                                        </div>
                                        <?php $this->endWidget(); ?>
                                    </div>
                                </li>
                                <?php endif; ?>
                            </ul>
                        </div>
                    </div>
                    <!-- end floor reply -->
                </div>
            </div>
            <div class="clear"></div>
        </div>

        <?php
        $floorID++;
    endif;
endforeach;
?>
